﻿var MobileCom = new Object();
MobileCom.getQueryString = function (name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}
MobileCom.GetUserCode = function (callback) {
    var Code = MobileCom.getQueryString("code");
    $.get('/View/Comon/ComBaseAPI.ashx?Action=GetUserCodeByCode&code=' + Code, function (UserCode) {
        if (UserCode=="") {
            window.location.href = "Msg.html";
        } else {
            $("#hidUserCode").val(UserCode);
            return callback.call(this, UserCode);
        }
    })
}
MobileCom.AlertMsg = function (content) {
    layer.open({
        content: content,
        btn: ['确认']
    });
}
MobileCom.getnowdate = function (format) {
    var now = new Date();

    var year = now.getFullYear();       //年
    var month = now.getMonth() + 1;     //月
    var day = now.getDate();            //日
    var clock = year + "-";

    if (format == "yyyy-mm") {
        if (month < 10)
            clock += "0";
        clock += month + "-";
    }

    if (format == "yyyy-mm-dd") {
        if (month < 10)
            clock += "0";
        clock += month + "-";
        if (day < 10) {
            clock += "0";
        }
        clock += day + "-";
    }
    return (clock.substr(0, clock.length - 1));

}
MobileCom.setCookie=function(name, value,t) {
    var Days = 30;
    var exp = new Date();
    if (t) {
        exp.setTime(exp.getTime() + parseInt(t) * 24 * 60 * 60 * 1000);
    } else {
        exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000);
    }
    document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString() + ";path=/";
}
MobileCom.getCookie=function(name) {
    var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

    if (arr = document.cookie.match(reg))

        return unescape(arr[2]);
    else
        return null;
}
MobileCom.delCookie = function (name) {
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval = MobileCom.getCookie(name);
    if (cval != null)
        document.cookie = name + "=" + cval + ";expires=" + exp.toGMTString() + ";path=/";
}
MobileCom.convstr = function (str, len) {
    str = str.replace(/&nbsp;/ig, "").replace(/<[^>]+>/g, "");
    if (len) {
        return str.length > len ? str.substr(0, len) + "..." : str;
    }
    else {
        return str.length > 10 ? str.substr(0, 10) + "..." : str;
    }
}
MobileCom.compareDate = function (strdate1, strdate2)
{
    var arr1 = strdate1.split("-");
    var time1 = new Date(arr1[0], arr1[1] - 1, arr1[2]);
    var times1 = time1.getTime();

    var times2 = 0;
    if (strdate2 == "") {
        times2 = new Date().getTime();
    }
    else {
        var arr2 = strdate2.split("-");
        var time2 = new Date(arr2[0], arr2[1] - 1, arr2[2]);
        times2 = time2.getTime();
    }

    if (times1 > times2) {
        return false;
    }
    else {
        return true;
    }
}
MobileCom.getqjstatus = function (status, status1, isforbid) {
    var sts = "";
    if ((isforbid == "Y" && status1 == 1) || (isforbid == "N" && status == 1)) {
        sts = '1';

    } else if (status1 == -1 || status == -1) {
        sts = '2';
    } else {
        sts = '0';
    }
    return sts;
}